function save() {
    var titles = document.querySelectorAll('.edit-title,.edit-label');
    let arr = [];
// 遍历每个元素  
    titles.forEach(function (title) {
        // 打印元素的文本内容到控制台
        if (title.querySelector(".stock-tooltip")) {
            title.querySelector(".stock-tooltip").remove();
        }
        title.textContent = title.textContent.replace(/[0-9]+\/[0-9]+/g, "");
        title.textContent = title.textContent.replace(/\*|^\s*|\s*$/g, "");
        if (title.textContent.includes("商品图片")) {
            let a;
        }
        p = title.closest(".attribute-select-item,.edit-row");
        if (title.textContent != "" && p != null) {
            el = p.querySelector(".shopee-selector__inner");
            if (el != null) {
                let value = el.textContent;
                if (title != null && el != null) {
                    value = value.replace(/[0-9]+\/[0-9]+/g, "");
                    value = value.replace(/\*|^\s*|\s*$/g, "");
                    console.log(title.textContent + ":" + value);
                    arr.push({name: title.textContent, value: value});
                }
            }
        }


        p = closet(title, "edit-row");
        if (title.textContent != "" && p != null) {
            el = p.querySelectorAll("input,textarea,img,.multiple-scroll-selector-tag");
            value = "";
            for (let i = 0; i < el.length; i++) {
                if (title != null && el[i] != null) {
                    if (el[i].tagName == "INPUT" || el[i].tagName == "TEXTAREA") {
                        value = value + "," + el[i].value.replace(/[0-9]+\/[0-9]+/g, "");
                        value = value.replace(/\*|^\s*|\s*$/g, "").replace(/^\s*/g, "");
                    } else if (el[i].tagName == "IMG") {
                        el.forEach(el2 => {
                            value = value + "," + el2.getAttribute("src");
                        })
                    } else if (el[i].classList.contains('multiple-scroll-selector-tag')) {
                        el.forEach(el2 => {
                            value = value + "," + el2.querySelector("span").textContent;
                        })
                    }
                }
            }
            value = value.replace(/^,/, "");
            console.log(title.textContent + ":" + value);
            arr.push({name: title.textContent, value: value});
        }

    });
    const queryString = window.location.search;
    const params = new URLSearchParams(queryString);
    const item_id = params.get('item_id');
    const url = window.location.href;
    fetch('https://shop.shante.me/yunshop/au3/saveprotype.php?item_id=' + item_id + "&XDEBUG_SESSION_START=54543", {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({url: url, item_id: item_id, arr: arr})
    })
        .then(response => response.json())
        .then(data => console.log(data))
        .catch(error => console.error(error));
}

function closet(el, className) {
    while ((el = el.parentElement) && el.nodeType === 1) {
        if (el.classList.contains(className)) {
            return el;
        }
    }
    return null;
}  